import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:qaun_ni_dev/provider/admin_provide.dart';


class AdminUpdate extends StatelessWidget {
  var adminData;
  AdminUpdate(this.adminData);


  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text('更新管理员信息'),
      ),
      body: Container(
        padding: EdgeInsets.all(12),
        child: ListView(
          children: <Widget>[
            _inputText(context),
          ],
        )
      ),
    );
  }

  Widget _inputText(context) {
    TextEditingController userAccount = TextEditingController(text: adminData.userAccount);
    TextEditingController remark = TextEditingController(text: adminData.remark);
    TextEditingController userPassword = TextEditingController();
    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: userAccount,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '账号名称',
              hintText: '请输入你的新账号名',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: remark,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '账号备注',
              hintText: '请输入你的备注信息',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.only(bottom: 15),
          child: TextField(
            controller: userPassword,
            readOnly: false,
            decoration: InputDecoration(
              labelText: '账号密码',
              hintText: '请输入你的新的密码',
              border: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.pink,
                ),
              ),
            ),
          ),
        ),
        RaisedButton(
          child: Text('提交修改'),
          onPressed: () {
            var formData = {
              'userAccount':userAccount.text,
              'remark':remark.text,
              'userPassword':userPassword.text,
              'id':adminData.id
            };
            Provider.of<AdminProvide>(context,listen: false).updateAdminInfo(context,formData);
          },
        ),
        RaisedButton(
          child: Text('重置数据'),
          onPressed: () {
            userAccount.text = '';
            remark.text = '';
          },
        ),
      ],
    );
  }


}
